#include "settingdialog.h"
#include <DWidgetUtil>
#include <DTitlebar>
#include <QLayout>
#include <DTitlebar>
#include <QListWidgetItem>

SettingDialog::SettingDialog(QWidget *parent) : DMainWindow(parent)
{
    moveToCenter(this);
//    titlebar()->setEmbedMode(true);
    setWindowIcon(QIcon::fromTheme("deepin-browser"));
    titlebar()->setTitle(tr("Settings"));
    w=new QWidget;
    setCentralWidget(w);
    Init();
    setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
}

SettingDialog::~SettingDialog()
{

}

void SettingDialog::Init()
{
    titleList=new DListWidget;
    stackedWidget=new QStackedWidget;
    DFrame *frameTitle=new DFrame;
    DFrame *frame=new DFrame;
    BasicSettings* basicSettings=new BasicSettings;
    appearanceSettings=new AppearanceSettings;
    stackedWidget->addWidget(basicSettings);
    stackedWidget->addWidget(appearanceSettings);

    frame->setLineWidth(0);

    QFont titleList_font;
    titleList_font.setPointSize(14);

    frameTitle->setFixedWidth(200);
    titleList->setLineWidth(0);

    QListWidgetItem * base_item=new QListWidgetItem;
    base_item->setText(tr("Basic"));
    base_item->setFont(titleList_font);
    base_item->setSizeHint(QSize(48,48));
    QListWidgetItem * appearance_item=new QListWidgetItem;
    appearance_item->setText(tr("Appearance"));
    appearance_item->setFont(titleList_font);
    appearance_item->setSizeHint(QSize(48,48));
    connect(titleList,&QListWidget::currentItemChanged,[=](QListWidgetItem* item){
        if(item==base_item)
            stackedWidget->setCurrentWidget(basicSettings);
        if(item==appearance_item)
            stackedWidget->setCurrentWidget(appearanceSettings);

    });
    titleList->addItem(base_item);
    titleList->addItem(appearance_item);

    QPalette plt;
    plt.setColor(QPalette::Background,QColor(40,40,40,255));
    stackedWidget->setPalette(plt);





    QHBoxLayout* w_layout=new QHBoxLayout;
    QHBoxLayout* w2_layout=new QHBoxLayout;
    QHBoxLayout* ft_layout=new QHBoxLayout;
    QHBoxLayout* f_layout=new QHBoxLayout;
    w_layout->addWidget(frameTitle);
    ft_layout->addWidget(titleList);
    frameTitle->setLayout(ft_layout);
    frameTitle->setLineWidth(0);
    w_layout->addLayout(w2_layout);
    w2_layout->setMargin(8);
    w2_layout->addWidget(frame);
    frame->setLayout(f_layout);
    f_layout->addWidget(stackedWidget);
    w_layout->setSpacing(0);
    w_layout->setMargin(0);
    w->setLayout(w_layout);

    titleList->setCurrentItem(base_item);

    setFixedSize(680,640);
    connect(appearanceSettings,&AppearanceSettings::EffectChange,[=](bool open,quint8 value){
        emit SettingDialog::EffectChange(open,value);
    });
}
